'use strict';

var service = module.exports = {};

service.handleText = function(message) {
  return function *(next) {
    if (message.Content === 'oauth') {
      return {type: "text", content: '<a href="' + this.request.protocol + '://' + this.request.hostname +'/v1/wechat/oauth">oauth</a>'};
    } else {
      return {type: "text", content: 'this is image message'};
    }
    yield next;
  };
};

service.getToken = function(cache, weChatAccessToken) {
  return function *(next) {
    var token = yield cache.get(weChatAccessToken);
    return JSON.parse(token);
  };
};

service.setToken = function(cache, weChatAccessToken) {
  return function *(next) {
    return yield cache.set(weChatAccessToken, JSON.stringify(next));
  };
};

service.getOpenIdToken = function(cache) {
  return function *(openId) {
    var token = yield cache.get(openId);
    return JSON.parse(token);
  };
};

service.setOpenIdToken = function(cache, openId) {
  return function *(openId, token) {
    return yield cache.set(openId, JSON.stringify(token));
  };
};

service.findRobruleByOpenId = function(openId) {};
